package cn.itlaobing.web.servlet;

import cn.itlaobing.model.Station;
import cn.itlaobing.model.StationDto;
import cn.itlaobing.service.StationService;
import cn.itlaobing.service.impl.StationServiceImpl;
import cn.itlaobing.web.annotation.RequestMapping;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 实现查询车票的servlet、
 * */
@WebServlet(value = "/user/*", loadOnStartup = 1)
public class StationServlet extends BaseServlet {
    @RequestMapping("/query")
    public void query(HttpServletRequest request, HttpServletResponse response)throws IOException,ServletException{
        request.setCharacterEncoding("utf-8");
        String num=request.getParameter("trainNum");
        String start=request.getParameter("station1");
        String end=request.getParameter("station2");
        StationService ss=new StationServiceImpl();
        StationDto stationDto=ss.authentication(num,start,end);
        if(stationDto==null){
            request.setAttribute("msg","查询不到该信息");
            request.getRequestDispatcher("/query.jsp").forward(request,response);
            return;
        }
        //有信息
        request.getSession().setAttribute("stationDto",stationDto);
        request.getRequestDispatcher("/WEB-INF/view/ok.jsp").forward(request,response);
    }
}
